Skip to content

feat: finops_snowflake_savings: read-only Snowflake warehouse savings check - #1786

Merged
shreyastelkar merged 4 commits into
feat/databricks-savings-toolfrom
feat/snowflake-savings-tool
Nov 20, 2026
Merged

shreyastelkar merged 4 commits into
feat/databricks-savings-toolfrom
feat/snowflake-savings-tool

Conversation

@shreyastelkar

@shreyastelkar shreyastelkar commented Nov 19, 2026 •

Copy link
Copy Markdown

Summary (for people)

  • Why: this does for Snowflake what #1762 does for Databricks. A user can check their own Snowflake account for warehouse savings from their machine, or from Claude Code's /savings, without sending usage data to Altimate.
  • Before → after: Before, altimate-code had no Snowflake savings check. After, finops_snowflake_savings reads seven days of the account's usage. It returns each saving with a monthly dollar range and its evidence. The checks cover warehouses that sit idle, could run one size smaller, keep an unneeded extra cluster, or restart so often that a billed minute is paid twice.
  • Who is affected: Users with a Snowflake connection, once this ships. The check runs only with confirm: true, and the agent asks first, because a run can resume a suspended warehouse that then bills. Other Snowflake queries are unchanged: the new cancel path is opt-in.
  • Before it can merge:
    • The base. This is stacked on #1762 (base feat/databricks-savings-tool), which merges first.
    • The core release. It needs an altimate-core release that exports snowflakeSavings (core #788), plus a pin bump. Until then, a confirmed run says this build has no Snowflake rules, before any warehouse query.

Details (for agents/reviewers)

Issue for this PR

None.

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

  • Facts. The tool lists warehouses with SHOW WAREHOUSES. To report on seven days, it reads up to eleven days of SNOWFLAKE.ACCOUNT_USAGE. Days are UTC, and the window ends at least six hours ago, past the views' latency.
  • Rules. altimate-core's snowflakeSavings decides what qualifies and what it saves. It returns the same report shape as the Databricks tool.
  • Price. A credit is priced from the account's rate sheet when it can be read in dollars, otherwise at a stated $3.00.
  • Asks first. Without confirm: true nothing runs. With it, the check stops after 9 minutes, connecting included, or sooner at the run's time budget.
  • Stopping for real. The Snowflake driver gains the opt-in cancelAfterMs. Past the limit, or when the session stops, the statement is cancelled on Snowflake. A statement still waiting on a reconnect is never sent.
  • Assessment mode. When it loads, snowflake-sdk probes the AWS, Azure and GCP metadata services. In this mode the driver sets SNOWFLAKE_DISABLE_PLATFORM_DETECTION first, so the SDK skips them.
  • Limits, as the hosted product has them. An active period starts at a resume, ends at the next event, and must overlap at least one query, as the core rules' spec defines it. So a warehouse that never suspended in the window, or a period with no query, gets no idle finding. A bounce counts within one UTC day.
  • Wiring and docs. The tool is registered where finops_databricks_savings is. Docs are on the FinOps tools page.

How did you verify your code works?

At head ade5a6b, rebased onto #1762's current head:

  • tsgo --noEmit: packages/opencode and packages/drivers both clean.
  • Drivers, databricks-deadline and snowflake-deadline: 26 pass.
  • The Snowflake and Databricks savings suites, plus the analyst, workspace and telemetry suites: 1,853 pass in 61 files.
  • assessment-zero-egress: 23 pass. That includes the Snowflake case with the real driver loaded: without assessment mode the proxy sees the metadata probes, and with it only the account.
  • Live, on Altimate's own Snowflake account, with the packaged CLI, a throwaway home and a read-only role: 9 findings in 43 s. The only hosts contacted were the Snowflake account and the Databricks workspace. The call without confirm contacted nothing.
  • Against stored data. For a past week, the measured credits equal the hosted product's on all nine active warehouses, and all 1,275 stored active periods match.
  • Certificate revocation. The SDK's revocation requests use an HTTPS agent that Bun does not use, so the packaged CLI makes none.
  • Large results. A result big enough for Snowflake to serve from its cloud storage would add that host. The live run did not need it, and the docs say so.
  • Not covered: cancellation at the limit was not exercised live. The driver tests cover it with a fake SDK. The live run is repeated on the final head before merge.

Cost side effects

Yes, warehouse queries. A confirmed run sends six statements:

  • SHOW WAREHOUSES, which needs no warehouse;
  • five queries on the connection's warehouse, which Snowflake resumes if it is suspended and auto-resume is on.

The usage queries scan up to eleven days of ACCOUNT_USAGE, so their work grows with query history. They are capped by the explicit confirm, one 9-minute limit for the whole run with server-side cancel, and a row limit per query. No model calls.

Screenshots / recordings

Not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR
  • I checked for cost side effects (model calls, queries or cloud resources that grow with user data) and described them, or wrote "none"

🤖 Generated with Claude Code


Summary by cubic

Adds the finops_snowflake_savings check, the Snowflake counterpart to the Databricks savings tool. Users can check their own account for warehouse savings from their machine or the /savings tool, without sending usage data to Altimate.

How it works

  • Reads seven days of usage from SHOW WAREHOUSES and SNOWFLAKE.ACCOUNT_USAGE, returning each saving with a monthly dollar range and evidence.
  • Catches idle warehouses, warehouses that could run one size smaller, unneeded extra clusters, and frequent restarts that double-bill a minute.
  • Runs only with confirm: true and stops after 9 minutes, because a run can resume a suspended warehouse that then bills.
  • Prices a credit from the account's rate sheet when available, otherwise at $3.00.
  • The Databricks savings check now also reports workspaces_checked, counting distinct workspaces across every checked row, with or without a finding or SQL warehouse.

Driver changes

  • The Snowflake driver gains opt-in cancelAfterMs, cancelling statements server-side past the limit or when the run stops.
  • In assessment mode, the driver sets SNOWFLAKE_DISABLE_PLATFORM_DETECTION so the SDK skips its cloud metadata probes.

Depends on the Databricks savings PR (#1762) merging first, plus an altimate-core release that exports snowflakeSavings and a pin bump.

Written for commit 89567af. Summary will update on new commits.

View guided diff

shreyastelkar and others added 3 commits November 19, 2026 15:50
…tays off cloud metadata in assessment mode

- Past the deadline, or when the signal aborts, the statement is cancelled on Snowflake. One still waiting
  on a reconnect is never sent. Calls without `cancelAfterMs` run as before.
- When it loads, snowflake-sdk probes the AWS, Azure and GCP metadata and identity services. A run that
  promises to contact only the warehouse now turns that off.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Measures warehouse usage from `SHOW WAREHOUSES` and `ACCOUNT_USAGE`, read-only, and hands the facts
and the price of a credit to altimate-core. It runs only with `confirm: true` and stops after 9 minutes.
Assessment mode and the zero-egress suite cover it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Also: the rate query takes one price above zero, a stop cancels every
statement sent, unused warehouses get ids that cannot collide, account
names stay on one line, and the driver egress test no longer needs the
core rules.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 9eabadd9-aa4a-4e24-b6c9-4480911a7e15

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 15 files

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

@kilo-code-bot

kilo-code-bot Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Code Review Summary

Status: 4 Issues Found | Recommendation: Address in a follow-up (PR merged)

Reviewed incrementally from ade5a6b5 to 89567af6. The incremental change (a Databricks workspaces_checked count) is small and internally consistent; the three earlier suggestions remain in the code and are carried forward.

Overview

Severity Count
CRITICAL 0
WARNING 0
SUGGESTION 4
Issue Details (click to expand)

SUGGESTION

File Line Issue
packages/opencode/src/altimate/native/finops/databricks-savings.ts 568 workspaces_checked is set and copied to metadata, but formatSavings still prints only warehouses/clusters/jobs and the shipped surfaces (default tool view, MCP adapter, altimate tool run without --json) forward only output, so the new count never reaches the user or the agent. Add it to the counted line or drop the field.
packages/opencode/src/altimate/tools/finops-snowflake-savings.ts 6 dollars is imported but never used
packages/opencode/src/altimate/native/finops/snowflake-savings.ts 221 The cloud-credits share divides by d.cloud_credits behind an IFF guard; NULLIF(d.cloud_credits, 0) keeps a zero-cloud-credit day from failing the whole query-history read
packages/opencode/src/altimate/native/finops/snowflake-savings.ts 455 num/records/rulesEngine/beforeStop/read/optional duplicate databricks-savings.ts, and the two beforeStop copies have already diverged on the early-abort path
Files Reviewed (7 files)

Incremental diff:

  • packages/opencode/src/altimate/native/finops/databricks-savings.ts - 1 issue
  • packages/opencode/src/altimate/native/types.ts - 0 issues
  • packages/opencode/src/altimate/tools/finops-databricks-savings.ts - 0 issues
  • packages/opencode/test/altimate/finops-databricks-savings.test.ts - 0 issues

Carried forward after targeted re-check of current code:

  • packages/opencode/src/altimate/tools/finops-snowflake-savings.ts - 1 issue
  • packages/opencode/src/altimate/native/finops/snowflake-savings.ts - 2 issues
Incremental notes
  • workspaces_checked dedupes workspace_id across warehouse, cluster and job rows, trims whitespace, drops empty/null ids, and runs after the core-refusal fallback empties clusters/jobs, so it matches the *_checked counts. The new test uses a BigInt id and a null id, and reset teardown is in place.
  • The three earlier suggestions were re-verified at HEAD (dollars still unused, IFF division unchanged, helper duplication unchanged); the author marked them as below this PR's fix bar, but the code is unchanged, so they stay listed.

Fix these issues in Kilo Cloud

Previous Review Summary (commit ade5a6b)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit ade5a6b)

Status: 3 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 0
SUGGESTION 3
Issue Details (click to expand)

SUGGESTION

File Line Issue
packages/opencode/src/altimate/tools/finops-snowflake-savings.ts 6 dollars is imported but never used
packages/opencode/src/altimate/native/finops/snowflake-savings.ts 221 The cloud-credits share divides by d.cloud_credits behind an IFF guard; NULLIF(d.cloud_credits, 0) keeps a zero-cloud-credit day from failing the whole query-history read
packages/opencode/src/altimate/native/finops/snowflake-savings.ts 455 num/records/rulesEngine/beforeStop/read/optional duplicate databricks-savings.ts, and the two beforeStop copies have already diverged on the early-abort path

The inline comment at snowflake-savings.ts:159 (bounces that cross UTC midnight) restates the existing comment on line 163 of the same block; that defect is tracked there and is not counted twice here.

Files Reviewed (15 files)
  • docs/docs/data-engineering/tools/finops-tools.md - 0 issues
  • packages/drivers/src/snowflake.ts - 0 issues
  • packages/drivers/src/types.ts - 0 issues
  • packages/drivers/test/snowflake-deadline.test.ts - 0 issues
  • packages/opencode/src/agent/agent.ts - 0 issues
  • packages/opencode/src/altimate/native/finops/register.ts - 0 issues
  • packages/opencode/src/altimate/native/finops/snowflake-savings.ts - 3 issues
  • packages/opencode/src/altimate/native/types.ts - 0 issues
  • packages/opencode/src/altimate/tool-cli/allow-list.ts - 0 issues
  • packages/opencode/src/altimate/tools/finops-databricks-savings.ts - 0 issues
  • packages/opencode/src/altimate/tools/finops-snowflake-savings.ts - 1 issue
  • packages/opencode/src/tool/registry.ts - 0 issues
  • packages/opencode/test/agent/analyst-data-explorer.test.ts - 0 issues
  • packages/opencode/test/altimate/assessment-zero-egress.test.ts - 0 issues
  • packages/opencode/test/altimate/finops-snowflake-savings.test.ts - 0 issues

The SQL windows (-169 hours, the 23:00-shifted idle day, the -7/-9/-10 read ranges) are internally consistent: usage and idle days both cover the seven days before the window end. Effect, config-resolution, permission and V2-surface concerns do not apply to these files. SQL semantics were checked by inspection only; no warehouse query could be run in this read-only session.

Fix these issues in Kilo Cloud


Reviewed by deepseek-v4.1-flash-1017 · Input: 88.7K · Output: 17.4K · Cached: 2.3M

Review guidance: REVIEW.md from base branch feat/databricks-savings-tool

…cked

`workspaces_checked` counts the distinct workspaces across every warehouse, cluster and job row checked, including workspaces with no finding or no SQL warehouse.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@shreyastelkar
shreyastelkar merged commit 89567af into feat/databricks-savings-tool Nov 20, 2026
@shreyastelkar
shreyastelkar deleted the feat/snowflake-savings-tool branch November 20, 2026 00:25
@shreyastelkar

Copy link
Copy Markdown
Author

Combined into #1762 at the owner's request; its commits are now on that branch. GitHub shows this PR as merged because its head was fast-forwarded onto its base branch (feat/databricks-savings-tool); nothing was merged into main.

window,
warehouse: resolved.warehouse,
ran_on: runsOn,
workspaces_checked: workspaces.size,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SUGGESTION: The new count never reaches the output the user or the agent reads

workspaces_checked is set here and copied into the tool metadata, but formatSavings (finops-databricks-savings.ts:90-95) still prints only warehouses, clusters and jobs, and the shipped surfaces forward output, not metadata: the default tool view renders output, and the MCP adapter (mcp-server/adapter.ts) and altimate tool run (non---json) return only output to the model. So the number this commit adds is invisible in the Claude Code//savings path it was meant for; only --json and session export expose it.

Either add it to the counted line in formatSavings (e.g. 1 SQL warehouses, 2 all-purpose clusters, 2 jobs checked across 3 workspaces) or drop the field and its test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant